from common.BasePages import BasePage


class ScreenMonitor(BasePage):
    # 大屏监控
    def screen_monitor_url(self):
        self.goto_url("screenMonitor")

    def create_screen_monitor(self):
        with self.page.expect_popup() as self.page1_info:
            self.page.get_by_role("button", name="新增").click()
        self.page1 = self.page1_info.value
        self.page1.get_by_role("textbox", name="* 大屏名称:").click()
        self.page1.get_by_role("textbox", name="* 大屏名称:").fill("张院龙大屏监控")
        self.page1.get_by_role("button", name="创建大屏").click()
        self.page1.locator(".head_btn > .iconfont").first.click()
        self.page1.get_by_role("button", name="是").click()
        self.assert_alert_content("大屏配置保存成功")

    def edit_screen_monitor_name(self):
        self.page.get_by_role("cell", name="张院龙大屏监控 ").locator("i").click()
        self.page.get_by_role("cell", name="张院龙大屏监控").get_by_role("textbox").fill("张院龙大屏监控22")
        self.page.get_by_role("cell", name="张院龙大屏监控").get_by_role("textbox").press("Enter")

    def delete_screen_monitor(self):
        self.page.locator(
            ".el-table__fixed-body-wrapper > .el-table__virtual-wrapper > div > .el-table__body > tbody > tr > .el-table_8_column_120 > .cell > .basicTableBtnBox > .el-icon-delete").first.click()
        self.page.get_by_role("button", name="确定").click()
        self.assert_alert_content("删除成功")

    def set_default(self):
        # 设置默认
        self.click_more_functions("大屏监控","设置默认")
        self.page.get_by_role("button", name="确定").click()
        self.assert_alert_content("设置成功!")

    def cat_history(self):
        # 查看历史
        self.click_more_functions("大屏监控","监控")
